<%@ page contentType="text/html;charset=UTF-8" %>
<%@ taglib prefix="form" uri="http://www.springframework.org/tags/form" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<c:set var="ctx" value="${pageContext.request.contextPath}"/>

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>导入邮箱数据 - Powered By LIUSANY</title>
<script type="text/javascript">
$().ready(function(){
<c:if test="${teststatus==false}">
$.dialog({type: "warn", content: "亲、您还未经过成功的邮件测试哦", width: 380, modal: true, autoCloseTime: 3000});
$("#submitButton").attr("disabled", true);
</c:if>
});
</script>
<!--
<script type="text/javascript" src="${ctx}/template/common/js/jquery.form.js"></script>


<script type="text/javascript">
$().ready(function() {




	$("#inputForm").submit(function() {
		$("#id").val($("#idSelect").val());
		$("#maxResults").val($("#maxResultsInput").val());
	});

	var isInitialized = false;
	var buildCount = 0;
	var buildTime = 0;
	$("#inputForm").ajaxForm({
		dataType: "json",
		beforeSubmit: function(data) {
			var maxResultsInputValue = $("#maxResultsInput").val();
			if ($.trim(maxResultsInputValue) == "") {
				$.message({type: "warn", content: "请输入每次更新数!"});
				return false;
			}
			if (!/^[1-9]\d*$/.test(maxResultsInputValue)) {
				$.message({type: "warn", content: "每次更新数必须为正整数!"});
				return false;
			}
			
			if (!isInitialized) {
				isInitialized = true;
				$("#idSelect").attr("disabled", true);
				$("#maxResultsInput").attr("disabled", true);
				$("#submitButton").attr("disabled", true);
				$("#statusTr").show();
				$("#status").text("正在进行发送操作,请稍后...");
			}
		},
		success: function(data) {
			buildCount += data.buildCount;
			buildTime += data.buildTime;
			if (data.status == "EMAIL_SENDING") {
				var maxResults = Number($("#maxResults").val());
				var firstResult = Number(data.firstResult);
				$("#status").text("正在发送邮件[" + (firstResult + 1) + " - " + (firstResult + maxResults) + "],请稍后...");
				$("#firstResult").val(firstResult);
				$("#inputForm").submit();
			} else if(data.status == "TASK_EXERUN"){
			  setInterval(auto,3000)
			}else if (data.status == "PRODUCT_FINISH") {
				$("#firstResult").val("0");
				$("#statusTr").hide();
				$("#idSelect").attr("disabled", false);
				$("#maxResultsInput").attr("disabled", false);
				$("#submitButton").attr("disabled", false);
				
				var time;
				if (buildTime < 60000) {
					time = (buildTime / 1000).toFixed(2) + "秒";
				} else {
					time = (buildTime / 60000).toFixed(2) + "分";
				}
				$.dialog({type: "success", content: "邮件发送成功! [发送总数: " + buildCount + " 耗时: " + time + "]", width: 380, modal: true, autoCloseTime: 3000});
				isInitialized = false;
				buildCount = 0;
				buildTime = 0;
			}
		}
	});

})
</script>
-->
</head>
<body class="input">
	<div class="bar">
		邮件发送
	</div>
	<div class="body">
		<form id="inputForm" action="${ctx}/admin/email/send" method="post">
			<input type="hidden" id="id" name="id" value="" />
			<!-- <input type="hidden" id="maxResults" name="maxResults" value="" /> -->
			<input type="hidden" id="firstResult" name="firstResult" value="0" />
			<table class="inputTable">
				<tr>
					<th>
						每次发送数量
					</th>
					<td>
						<input type="text" id="maxResultsInput" name="maxResults" class="formText" value="10000" />
					</td>
				</tr>
				<tr id="statusTr" class="hidden">
					<th>
						&nbsp;
					</th>
					<td>
						<span class="loadingBar">&nbsp;</span>
						<p id="status"></p>
					</td>
				</tr>
			</table>
			<div class="buttonArea">
				<input type="submit" id="submitButton" class="formButton" value="执行任务" hidefocus />&nbsp;&nbsp;
				<input type="button" class="formButton" onclick="window.history.back(); return false;" value="返  回" hidefocus />
			</div>
		</form>
	</div>
</body>
</html>